#include <avr/interrupt.h>
#include <avr/io.h>
// #####################################
// File     : motor.c
// Author   : Chris Meaclem, Chris McPherson, Isaac, Andrew Poland
// Date     : 28/07/2011
// Release  : Intermediate
// Purpose  : Library to provide control for motors via motor driver
// Notes    : 
// #####################################

#define ENABLE(x)	(1<<(x))
#define DISABLE(x)	(0<<(x))

#define ENABLE_LEFT_SENSOR DISABLE(MUX0)
#define ENABLE_RIGHT_SENSOR ENABLE(MUX0)

ISR(ADC_vect){
	
	/*	handle interrupt for when Sensor is read.
	*	If Left Sensor
	*		IF black
	*			Set INT0
	*		Else
	*			clear INT0
	*
	*	Else
	*		If black
	*			set INT1
	*		Else
	*			clear INT0
	*	
	*/
}

/*	The external interrupts are triggered by the INT0, and INT1 pins. Observe that, if enabled, the
*	interrupts will trigger even if the INT0..1 pins are configured as outputs. This feature provides a
*	way of generating a software interrupt.
*/

/** positioned rightSensor as ADCPIN1. */
public static void setRightRead(){
	ADMUX |= ENABLE_RIGHT_SENSOR;
}

/** Positioned leftSensor as ADCPIN0. */
public static void setLeftRead(){
	ADMUX |= ENABLE_LEFT_SENSOR;	
}

public static void initialiseSensorReader(){
	//Enable Left Adjust Read so only one register has to be
	//checked when reading data from ADC.
	ADMUX |= ENABLE(ADLAR);
	
	ADCSRA |= ENABLE(ADFR);		// Select free running mode.
	ADCSRA |= ENABLE(ADIE);		// Enable interupt on read.
	ADCSRA |= ENABLE(ADPS0);	// Next three calls, set the prescaler.
	ADCSRA |= ENABLE(ADPS1);
	ADCSRA |= ENABLE(ADPS2);
	ADCSRA |= ENABLE(ADEN);		// Enable the ADC pin.
	
}


ISR(INT0_vect, INT1_vect){

	
	
}